package com.atguigu.exam;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * @author xbd
 * @create 2021-05-29 18:12
 */
public class NewsTest {
    public static void main(String[] args) {
        ArrayList<News> newslist = new ArrayList<>(3);

        newslist.add(new News<Society>("好消息，大降价","Ines","大降价大降价大降价啦"));
        newslist.add(new News<Society>("坏消息，大涨价","Ines","大涨价大涨价大涨价啦"));
        newslist.add(new News<Entertainment>("惊天大消息！是的我们有一个孩子","Tony","孩子在哪里在哪里在哪里"));

        /*遍历集合，打印新闻标题，将新闻标题截取字符串到10个汉字的长度。*/
        Iterator<News> iterator = newslist.iterator();
        while (iterator.hasNext()){
            News news = iterator.next();
            String title = news.getTitle();
            if(title.length() > 10){
                System.out.println(title.substring(0, 10) + "...");
            }else{
                System.out.println(title);
            }
        }
    }
}
